<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
    <button id="btn">添加节点</button>

    <script>
        // 1. 获取对象,注册点击事件
        const btn = document.querySelector('#btn')
        btn.addEventListener('click',function(){
            // 2.创建节点,增加内容
            const liNode = document.createElement('li')
            liNode.innerHTML = '哈喽!'
            // 3.追加到父元素的最后面
            document.querySelector('ul').appendChild(liNode)

            // 4.追加到父元素中的任意一个位置
            const ul = document.querySelector('ul')
            ul.insertBefore(liNode,ul.children[2])
        })
    </script>
</body>
</html>